﻿<navigation:Page 
  x:Class="Demo.OData.Views.NW" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  
 	xmlns:mac="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls"
	xmlns:mao="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls.OData"
	xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"						 
  xmlns:od="clr-namespace:System.Windows.Controls;assembly=Slma.OData"
  xmlns:service="clr-namespace:Demo.OData.NWService"
  xmlns:local="clr-namespace:Demo.OData"
  
           d:DesignWidth="800" d:DesignHeight="600"
           Title="Nortwind">
    <Grid x:Name="LayoutRoot">
    <!--data source-->
    <!-- Customers -->
    <od:ODataSource 
      x:Name="dsCustomers" EntitySetName="Customers" AutoLoad="True" 
      
      >
      <od:ODataSource.DataServiceContext>
        <service:NorthwindEntities />
      </od:ODataSource.DataServiceContext>
      <od:ODataSource.SortDescriptions>
        <od:SortDescriptionOData  PropertyName="CustomerID" Direction="Ascending"  />
      </od:ODataSource.SortDescriptions>
    </od:ODataSource>
    <!-- Orders -->
    <od:ODataSource 
      x:Name="dsOrders" EntitySetName="Orders" AutoLoad="False" ForeignKey="{Binding ElementName=dsCustomers, Path=CurrentPrimaryKey}"  
      LoadSize="99" IncludeTotalCount="False"
      >
      <od:ODataSource.DataServiceContext>
        <service:NorthwindEntities />
      </od:ODataSource.DataServiceContext>
    </od:ODataSource>
    <!-- Design -->
    <StackPanel>
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="Northwind Customers" FontWeight="Bold" Margin="0,0,10,0" />
        <TextBox x:Name="txbURL"  MinHeight="20" Text="{Binding ElementName=dsCustomers, Path=QueryURL}" TextWrapping="Wrap" 
                HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" BorderThickness="0" IsReadOnly="True" />
      </StackPanel>
      <HyperlinkButton Content="The source code of control below is here http://datagridtoolbar.codeplex.com" NavigateUri="http://datagridtoolbar.codeplex.com/" TargetName="_blank" />
      <mao:DataGridToolBarOData  
        x:Name="tb1" Height="45" Margin="0,0,0,2" AutoSubmit="False" 
        ButtonAddNewVisible="False" ButtonEditVisible="False" ButtonRemoveVisible="False"
				DataGrid="{ Binding ElementName=dgCustomers, Mode=OneTime }"	
				ODataSource="{ Binding ElementName=dsCustomers, Mode=OneTime}"
				>
        <mao:DataGridToolBarOData.ColumnsForFiltering>
          <mac:DataGridToolBarFilterItem ColumnName="CustomerID"  />
          <mac:DataGridToolBarFilterItem ColumnName="Country"  />
          <mac:DataGridToolBarFilterItem ColumnName="City"  />
          <mac:DataGridToolBarFilterItem ColumnName="Address"  />
        </mao:DataGridToolBarOData.ColumnsForFiltering>
        <mao:DataGridToolBarOData.Content>
          <data:DataPager x:Name="dpCustomers" PageSize="5" Source="{Binding ElementName=dsCustomers, Path=Data}" BorderThickness="0" Background="Transparent" ></data:DataPager>
        </mao:DataGridToolBarOData.Content>
      </mao:DataGridToolBarOData>

      <data:DataGrid 
        x:Name="dgCustomers" Height="170" AutoGenerateColumns="False" 	  
				IsReadOnly="True"							
				ItemsSource="{Binding ElementName=dsCustomers, Path=Data }"
				>
        <data:DataGrid.Columns>
          <data:DataGridTextColumn Binding="{Binding CustomerID}" Header="CustomeID" />
          <data:DataGridTextColumn Header="CompanyName"
						Width="300" MinWidth="50" MaxWidth="500"  
						Binding="{Binding CompanyName}" CanUserResize="True" />
          <data:DataGridTextColumn Binding="{Binding Country}" Header="Country" />
          <data:DataGridTextColumn Binding="{Binding City}" Header="City" />
          <data:DataGridTextColumn Binding="{Binding Address}" Header="Address" />
          <!--<data:DataGridTextColumn Binding="{Binding Path=StartTime, StringFormat=t}" Header="Start" CanUserSort="False" />
          <data:DataGridTextColumn Binding="{Binding Path=EndTime, StringFormat=t}" Header="End" CanUserSort="False" />-->
        </data:DataGrid.Columns>
      </data:DataGrid>
      <!--Orders-->
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="Orders" FontWeight="Bold" Margin="0,0,10,0" />
        <TextBox   MinHeight="20" Text="{Binding ElementName=dsOrders, Path=QueryURL}" TextWrapping="Wrap" VerticalAlignment="Stretch"  
                     HorizontalAlignment="Stretch"  IsReadOnly="True" BorderThickness="0" />
      </StackPanel>
      <data:DataGrid 
        x:Name="dgOrders" AutoGenerateColumns="False" 	  
				IsReadOnly="True"							
				ItemsSource="{Binding ElementName=dsOrders, Path=Data }" MinHeight="50">
        <data:DataGrid.Columns>
          <data:DataGridTextColumn Binding="{Binding Path=OrderDate, StringFormat=d}" Header="OrderDate" />
          <data:DataGridTextColumn Binding="{Binding Path=ShipName}" Header="ShipName" />
          <data:DataGridTextColumn Binding="{Binding Path=ShipAddress}" Header="ShipAddress" />
          
          
        </data:DataGrid.Columns>
      </data:DataGrid>

    </StackPanel>
  </Grid>
</navigation:Page>
